<?php

    //Load all php file
    include("ClassLoader/Loader.php");
    $loader = new Loader();
    $loader->load();
    $title = 'ySocial - A photo social network';
    $mainClass = 'main-full';
    $topWidget = '';
    $header = '';
    $baseurl = "/ySocial/";
    //Param parser
    #remove the directory path we don't want 
    $request = substr($_SERVER['REQUEST_URI'], strlen($baseurl));
    if (strpos($request, '?') != '') {
        $request = substr($request, 0, strpos($request, "?"));
    }
    #split the path by '/'
    $params = split("/", $request);
    $streamId = 1;

    switch (strtoupper($params[0])) {
        case "M":
            //$soapRequest = $_REQUEST['request'];
            $server = new bpServer("/ySocial/m/");
            //var_dump($server);
            $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
            $server->service($HTTP_RAW_POST_DATA);
            return;
            break;
        case "":
        case "HOME":
            $params[0] = "Home";
            $title = 'ySocial - Home';
            $bottomModule = 'BottomModule.php';
            break;
        case "SHOTS":
            break;
        case "HIGHLIGHTS":
            break;
        case "BUCKETS":
            $secondary = "BucketsSecondaryHTML.php";
            $mainClass = '';
            break;
        case "COLORS":
            $secondary = "ColorsSecondaryHTML.php";
            $mainClass = '';
            break;
        case "ABOUT":
            $hero = "AboutHeroHTML.php";
            $secondary = "AboutSecondaryHTML.php";
            $bottomModule = 'BottomModule.php';
            $mainClass = 'site';
            break;
        case "AJAX":
            if (file_exists("View/Master/$params[1]HTML.php"))
                include "View/Master/$params[1]HTML.php";
            return;
            break;
        case "USER":
            break;
        case "SIGNUP":
            $hero = "SignupHeroHTML.php";
            $secondary = "SignupSecondaryHTML.php";
            $bottomModule = 'BottomModule.php';
            $mainClass = '';
            break;
        default:
            $params[1] = $params[0];
            $params[0] = "profile";
            $bottomModule = 'BottomModule.php';
            $profile = "ProfileActionHTML.php";
            $secondary = "ProfileSecondaryHTML.php";
            $mainClass = '';
            $title = 'ySocial - Home';
            break;
    }
    $params[0] = ucfirst($params[0]);
    //Generate View
    $masterView = MasterView::getInstance();
    $masterView->mainView = "View/$params[0]/" . $params[0] . "ViewHTML.php";
    if ($header)
        $masterView->header = "View/$params[0]/$header";
    $masterView->topWidget = $topWidget;
    if ($hero)
        $masterView->hero = "View/$params[0]/$hero";
    if ($secondary)
        $masterView->secondary = "View/$params[0]/$secondary";
    if ($profile)
        $masterView->profile = "View/$params[0]/$profile";
    $masterView->title = $title;
    $masterView->mainClass = $mainClass;
    if ($bottomModule)
        $masterView->bottomModule = "View/$params[0]/$bottomModule";
    $masterView->params = $params;
    $masterView->baseUrl = $baseurl;
    $masterView->display("MasterPage.php");
?>


